<?php
	// define constants
	define("_PROJECT_DIR", realpath('../'));
	define("_LOCALE_DIR", _PROJECT_DIR .'/locale');
	define("_DEFAULT_LOCALE", 'ca_ES.UTF8'); 
	define("_PHP_GETTEXT_LIB",'/usr/share/php/php-gettext/');

	require_once(_PHP_GETTEXT_LIB.'gettext.inc');

	//Nom utilitzat per l'exemple localization_example.php
	$supported_locales = array('ca_ES.UTF8','es_ES.UTF8','en_GB.UTF8','fr_FR.UTF8');
	$encoding = 'UTF-8';
	
	//echo $_SERVER['HTTP_ACCEPT_LANGUAGE'];
	//Agafar el locale del paràmetre lang
	$locale = (isset($_GET['lang'])) ? $_GET['lang'] : _DEFAULT_LOCALE;

	// gettext setup
	T_setlocale(LC_MESSAGES, $locale);

	// Set the text domain as 'messages'
	$domain = 'messages';
	T_bindtextdomain($domain, _LOCALE_DIR);
	T_bind_textdomain_codeset($domain, $encoding);
	T_textdomain($domain); 

	/**
	echo('Llenguatges disponibles : (per posar a la url) <br />');
	foreach($supported_locales as $x) echo('?lang='.$x.'<br />');
	echo('Llenguatge seleccionat : '.$locale.'<br />');
	*/
?>
